import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }

        Solution solution = new Solution();
        int[] array = solution.avoidFlood(arr);
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }
    }
}


class Solution {
    public int[] avoidFlood(int[] rains) {
        int n = rains.length;
        int[] ans = new int[n];
        Map<Integer, Integer> fullDay = new HashMap<>();
        TreeSet<Integer> dryDay = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            int lake = rains[i];
            if (lake == 0) {
                ans[i] = 1;
                dryDay.add(i);
                continue;
            }
            Integer j = fullDay.get(lake);
            if (j != null) {
                Integer d = dryDay.higher(j);
                if (d == null) {
                    return new int[]{};
                }
                ans[d] = lake;
                dryDay.remove(d);
            }
            ans[i] = -1;
            fullDay.put(lake, i);
        }
        return ans;
    }
}